package com.ocom.human.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.ocom.common.entity.human.EntityVisitorApprover;
import com.ocom.common.enums.DataSourceEnum;
import com.ocom.common.enums.MasterSlaveEnum;
import com.ocom.common.utils.StringUtils;
import com.ocom.common.vo.human.GetVisitorApproverVo;
import com.ocom.human.dao.IDaoVisitorApprover;
import com.ocom.human.service.VisitorApproverService;
//import com.ocom.human.vo.GetVisitorApproverVo;
import com.ocom.mysql.aspect.DataSourceAspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VisitorApproverServiceImpl extends ServiceImpl<IDaoVisitorApprover, EntityVisitorApprover> implements VisitorApproverService {


    @Autowired
    private IDaoVisitorApprover iDaoVisitorApprover;
    /**
     * 获取审批负责人列表  (getVisitorApprover)
     *
     * @return*/
    @DataSourceAspect(type = DataSourceEnum.PART_DB,companyId = "comId",isMaster = MasterSlaveEnum.SLAVE)
    @Override
    public List<EntityVisitorApprover> GetVisitorApprover(Long comId, GetVisitorApproverVo getVisitorApproverVo) {
        QueryWrapper<EntityVisitorApprover> query = Wrappers.query();
        query.eq("com_id",getVisitorApproverVo.getComId());
        if (StringUtils.isNotNull(getVisitorApproverVo.getId()) && getVisitorApproverVo.getId() > 0){
            query.eq("id",getVisitorApproverVo.getId());
        }
        if (StringUtils.isNotEmpty(getVisitorApproverVo.getPName())){
            query.like("p_name",getVisitorApproverVo.getPName());
        }
        if (StringUtils.isNotNull(getVisitorApproverVo.getStatus())){
            query.eq("status",getVisitorApproverVo.getStatus());
        }
        query.last("order by CONVERT( p_name USING gbk ) COLLATE gbk_chinese_ci ASC,com_id");
        PageHelper.startPage(getVisitorApproverVo.getPage(),getVisitorApproverVo.getSize());
        return iDaoVisitorApprover.selectList(query);
    }

    /**
     * 添加审批负责人列表  (addVisitorApprover)
     * */
    @DataSourceAspect(type = DataSourceEnum.PART_DB,companyId = "comId",isMaster = MasterSlaveEnum.MASTER)
    @Override
    public void AddVisitorApprover(Long comId, EntityVisitorApprover entityVisitorApprover) {
        iDaoVisitorApprover.insert(entityVisitorApprover);
    }

    /**
     * 修改审批负责人列表  (updateVisitorApprover)
     * */
    @DataSourceAspect(type = DataSourceEnum.PART_DB,companyId = "comId",isMaster = MasterSlaveEnum.MASTER)
    @Override
    public void UpdateVisitorApprover(Long comId, EntityVisitorApprover entityVisitorApprover) {
        iDaoVisitorApprover.updateById(entityVisitorApprover);
    }

    /**
     * 删除审批负责人列表  (deleteVisitorApprover)
     * */
    @DataSourceAspect(type = DataSourceEnum.PART_DB,companyId = "comId",isMaster = MasterSlaveEnum.MASTER)
    @Override
    public void DeleteVisitorApprover(Long comId, Long id) {
        iDaoVisitorApprover.deleteById(id);
    }


}
